<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>动态属性</title>
</head>
<body>
<script>
    class Car {
        //公有对象，可直接调用
        constructor(make, model) {
            this.make = make;
            this.model = model;
            this._userGears = ['P','N','R','D'];//前面加下划线意为私有属性
            //this._userGear = this._userGears[0];
        }
        get userGear(){
            return this._userGear;
        }
        set userGear(value){
            if (this._userGears.indexOf(value) == -1){
                console.log("挡位不正确！");
            }else {
                this._userGear = value;
            }
        }
    }
    let car = new Car("宝马","550i");
    car.userGear = "A";
    console.log(car.userGear);

</script>
</body>
</html>